﻿using System;
using System.Linq;
using VSIXModel.Entitys;
using VSIXModel.Page;
namespace VSIXDomeDAL.Manage.User
{
    public class UserManage : BaseManage,IUserManage
    {
        public PageResult<VSIXDomeDAL.Manage.User.Dto.UserOutPutDto> GetUserPage(VSIXDomeDAL.Manage.User.Dto.CreateUserInputDto input)
        {
            return new PageResult<VSIXDomeDAL.Manage.User.Dto.UserOutPutDto>();
        }
        public void AddUser (VSIXDomeDAL.Manage.User.Dto.CreateUserInputDto input)
        {
            var entity = input.ToMap<UserEntity>();
            using (var db = new VSIXDbContext())
            {
                db.Users.Add(entity);
                db.SaveChanges();
            }
        }
        public void UpdateUser (VSIXDomeDAL.Manage.User.Dto.UpdateUserInputDto input)
        {
            using (var db = new VSIXDbContext())
            {
                var entity = db.Users.Where(c => c.Id == input.Id).FirstOrDefault();
                if (entity == null)
                    return;
                entity.Mapping(input);
                db.Users.Update(entity);
                db.SaveChanges();
            }
        }
        public void RemoveUser (int Id)
        {
            using (var db = new VSIXDbContext())
            {
                var entity = db.Users.Where(c => c.Id == Id).FirstOrDefault();
                if (entity == null)
                    return;
                db.Users.Remove(entity);
                db.SaveChanges();
            }
        }
        public VSIXDomeDAL.Manage.User.Dto.UserOutPutDto GetInfo(int Id)
        {
            return new VSIXDomeDAL.Manage.User.Dto.UserOutPutDto();
        }
    }
}
